package io.renren.modules.lanling.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.lanling.entity.InvoiceSubjectNameEntity;
import io.renren.modules.lanling.service.InvoiceSubjectNameService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

import static io.renren.modules.sys.shiro.ShiroUtils.getUserId;


/**
 * 发票科目名称表
 *
 * @author LANLING
 * @email lanling@gmail.com
 * @date 2018-11-08 16:46:13
 */
@RestController
@RequestMapping("lanling/invoicesubjectname")
public class InvoiceSubjectNameController {
    @Autowired
    private InvoiceSubjectNameService invoiceSubjectNameService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("lanling:invoicesubjectname:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = invoiceSubjectNameService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("lanling:invoicesubjectname:info")
    public R info(@PathVariable("id") Integer id){
        InvoiceSubjectNameEntity invoiceSubjectName = invoiceSubjectNameService.selectById(id);

        return R.ok().put("invoiceSubjectName", invoiceSubjectName);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("lanling:invoicesubjectname:save")
    public R save(@RequestBody InvoiceSubjectNameEntity invoiceSubjectName){
        invoiceSubjectName.setCreatDate(new Date( ));
        invoiceSubjectNameService.insert(invoiceSubjectName);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("lanling:invoicesubjectname:update")
    public R update(@RequestBody InvoiceSubjectNameEntity invoiceSubjectName){
        ValidatorUtils.validateEntity(invoiceSubjectName);
        invoiceSubjectNameService.updateAllColumnById(invoiceSubjectName);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("lanling:invoicesubjectname:delete")
    public R delete(@RequestBody Integer[] ids){
        invoiceSubjectNameService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }
    @RequestMapping("/queryList")
    public R queryList() {
        Long schoolId = getUserId();
        EntityWrapper<InvoiceSubjectNameEntity> entityWrapper = new EntityWrapper<>();
      //  entityWrapper.eq("school_id", schoolId);

        List<InvoiceSubjectNameEntity> InvoiceSubjectNameEntities = invoiceSubjectNameService.selectList(entityWrapper);
        return R.ok().put("list", InvoiceSubjectNameEntities);
    }
}
